<?php
session_start();
require "lib/db.php";
require "lib/orderdetail-function.php";
require "lib/product-function.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Order Detail</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>

<script>
	$(document).ready(function() {
       $("#order").css({"background-color":"#FFF",	
	"color":"#000"});
    });
</script>

<style>
	#content{
		overflow:scroll;
		height:510px;
		margin:2px 3px;
		opacity:0.8;
		text-align:center;
	}
	
	#order-amount-total{
		padding-right:170px;
		text-align:right;	
	}

</style>
</head>

<body>

<!--menu-->
<?php
require "menu.php";
?>

<?php
if(isset($_GET['orderid'])){
	$orderID = $_GET['orderid'];
	settype($orderID,"int");
}

$orderAmountTotal = 0;
?>

<!--content-->
<div id="content">
<table width="100%" border="1" cellspacing="0">
  <tr>
  	<th>OrderID</th>
    <th>Product Name</th>
    <th>Price</th>
    <th>Unit</th>
    <th>Product Number</th>
    <th>Amount Total(VND)</th>
  </tr>
	<?php
   	$listorderdetail = getListOrderDetailByOrderID($orderID);
	while($orderdetail = mysql_fetch_array($listorderdetail)){
		$productID = $orderdetail['ProductID'];
		settype($productID,"int");
		$product = mysql_fetch_array(getProductByID($productID));
		ob_start();
    ?>
  <tr>
  	<td>{OrderID}</td>
    <td>{ProductName}</td>
    <td>{Price}</td>
    <td>{Unit}</td>
    <td>{ProductNumber}</td>
    <td>{AmountTotal}</td>
  </tr>
 	<?php 
	$s = ob_get_clean();
	$s = str_replace("{OrderID}","$orderdetail[OrderID]",$s);
	$s = str_replace("{ProductName}","$product[ProductName]",$s);
	$s = str_replace("{Price}","$product[Price]",$s);
	$s = str_replace("{Unit}","$product[Unit]",$s);
	$s = str_replace("{ProductNumber}","$orderdetail[ProductNumber]",$s);
	$amountTotal = $product['Price']*$orderdetail['ProductNumber'];
	$orderAmountTotal = $orderAmountTotal + $amountTotal;
	$s = str_replace("{AmountTotal}","$amountTotal",$s);
	echo $s;
	}
	?>
</table>
<div id="order-amount-total">
	<b>Order Amount Total: <?php echo $orderAmountTotal; ?></b>
</div>
</div>

<!--footer-->
<?php
require "footer.php";
?>

</body>
</html>